package com.qidianit.mes.pro.controller;

import com.github.pagehelper.PageInfo;
import com.qidianit.mes.pojo.Result;
import com.qidianit.mes.pojo.pro.ProductionReport;
import com.qidianit.mes.pro.service.FeedbackService;
import com.qidianit.mes.pro.vo.FeedbackProduct;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.List;

/**
 * @Description:
 * @Author: shanzhe
 * @Date: 2025/9/26 - 16:29
 */
@RestController
@RequestMapping("/feedback")
public class FeedbackController {

    @Autowired
    private FeedbackService feedbackService;

/*
分页查询
 */
    @GetMapping("/list")
    public Result<PageInfo<FeedbackProduct>> queryProductionReportByMAnyTags(@RequestParam(value = "pageNum",defaultValue = "1") Integer pageNum,
                                                                             @RequestParam(value = "pageSize",defaultValue = "10") Integer pageSize,
                                                                             @RequestParam(value = "reportType",required = false) Integer reportType,
                                                                             @RequestParam(value = "workflowName",required = false) String  workflowName,
                                                                             @RequestParam(value = "productionOrderCode",required = false) String productionOrderCode,
                                                                             @RequestParam(value = "productCode",required = false) String productCode,
                                                                             @RequestParam(value = "productName",required = false) String productName,
                                                                             @RequestParam(value = "reporterName",required = false) String reporterName,
                                                                             @RequestParam(value = "approverName",required = false) String approverName,
                                                                             @RequestParam(value = "status",required = false) Integer status){
        return Result.success(feedbackService.queryProductionReportByMAnyTags(pageNum,pageSize,reportType,workflowName,productionOrderCode,productCode,productName,reporterName,approverName,status));
    }

    @PostMapping("/add")
    public Result addFeedback(@RequestBody ProductionReport productionReport) {
        productionReport.setUpdatedTime(LocalDateTime.now());
        productionReport.setStatus(30);
        productionReport.setProcessId(1L);
        productionReport.setReportTime(LocalDateTime.now());
        int result = feedbackService.addProductionReport(productionReport);
        return result == 1?Result.success():Result.error("操作失败");
    }

    @GetMapping("/id/{id}")
    public Result getFeedbackById(@PathVariable("id") Long id) {
        return Result.success(feedbackService.getProductionReportById(id));
    }

    @PutMapping("/update")
    public Result updateFeedback(@RequestBody ProductionReport productionReport) {
        productionReport.setUpdatedTime(LocalDateTime.now());
        int result = feedbackService.updateProductionReport(productionReport);
        return result == 1?Result.success():Result.error("操作失败");
    }

    @DeleteMapping("/delete/{id}")
    public Result deleteFeedbackById(@PathVariable("id") Long id) {
        int result = feedbackService.deleteProductionReportById(id);
        return result == 1?Result.success():Result.error("操作失败");
    }

    @DeleteMapping("/batchDelete/{ids}")
    public Result batchDeleteFeedbackByIds(@PathVariable("ids") List<Long> ids) {
        int result = feedbackService.batchDeleteProductionReportByIds(ids);
        return result == 1?Result.success():Result.error("操作失败");
    }
}
